/*
 * Copyright (C) 2011 CrystalRange
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.crystalrange.searching;

import com.googlecode.genericdao.search.Filter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class SearchOperators implements Serializable {

    private static final long serialVersionUID = 1L;
    
    private int searchOperatorId;
    private String searchOperatorSign;
    private String searchOperatorName;

    public int getSearchOperatorId() {
        return this.searchOperatorId;
    }

    public void setSearchOperatorId(int searchOperatorId) {
        this.searchOperatorId = searchOperatorId;
    }

    public String getSearchOperatorName() {
        return this.searchOperatorName;
    }

    public void setSearchOperatorName(String searchOperatorName) {
        this.searchOperatorName = searchOperatorName;
    }

    public String getSearchOperatorSign() {
        return this.searchOperatorSign;
    }

    public void setSearchOperatorSign(String searchOperatorSign) {
        this.searchOperatorSign = searchOperatorSign;
    }
    
    public SearchOperators() {
    }
    
    public SearchOperators(int searchOperatorId, String searchOpertorSign, String searchOperatorName) {
        this.searchOperatorId = searchOperatorId;
        this.searchOperatorSign = searchOpertorSign;
        this.searchOperatorName = searchOperatorName;
    }

    public static List<SearchOperators> getAllOperators() {
        List<SearchOperators> result = new ArrayList<SearchOperators>();

        // list position 0
        result.add(new SearchOperators(-1, "", "no operator"));
        // list position 1
        result.add(new SearchOperators(Filter.OP_EQUAL, "=", "equals"));
        // list position 2
        result.add(new SearchOperators(Filter.OP_NOT_EQUAL, "<>", "not equal"));
        // list position 3
        result.add(new SearchOperators(Filter.OP_LESS_THAN, "<", "less than"));
        // list position 4
        result.add(new SearchOperators(Filter.OP_GREATER_THAN, ">", "greater than"));
        // list position 5
        result.add(new SearchOperators(Filter.OP_LESS_OR_EQUAL, "<=", "less or equal"));
        // list position 6
        result.add(new SearchOperators(Filter.OP_GREATER_OR_EQUAL, ">=", "greater or equal"));
        // list position 7
        result.add(new SearchOperators(Filter.OP_ILIKE, "~", "ilike"));

        return result;
    }

    @Override
    public int hashCode() {
        return this.getSearchOperatorId();
    }

    public boolean equals(SearchOperators searchOperators) {
        return this.getSearchOperatorId() == searchOperators.getSearchOperatorId();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (obj instanceof SearchOperators) {
            SearchOperators searchOperators = (SearchOperators) obj;
            return this.equals(searchOperators);
        }

        return false;
    }
}
